/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package serwer;

import Serializable.ParsedCmd;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Marcin
 */
public class Connection {
    public static int SPORT = 8870;
    public static String HOST = "192.168.1.100";
    
    public static String hash(char[] a){
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("SHA-512");
            digest.reset();
            byte[] input = digest.digest(String.valueOf(a).getBytes("UTF-8"));
            input=digest.digest(input);
            Serwer.log(input.toString());
            return new String(input);   
        } catch (NoSuchAlgorithmException ex) {
            Serwer.log("Nieprawidłowe kodowanie");
            return null;
        } catch (UnsupportedEncodingException ex) {
            Serwer.log("Niewspierane enkodowanie");
            return null;
        }               
    }
    
    public static void Send(PrintWriter pW, String cmd){
        Serwer.log("Serwer: "+cmd);
        pW.println(cmd);
        pW.flush();
    }
    
    public static void Send(PrintWriter pW, ParsedCmd cmd){
        Serwer.log("Serwer: "+cmd);
        pW.println(cmd.toString());
        pW.flush();
    }
    
    public static void Init(PrintWriter pW){
        pW.println(new ParsedCmd("WUT?").toString());        
        pW.flush();  
    }
}
